<template>
  <div>
    <easy-dialog :is-show="isShowCheckDialog" @on-close="checkStatus">
      请检查你的支付状态！
      <div class="button" @click="checkStatus">
        支付成功
      </div>
      <div class="button" @click="checkStatus">
        支付失败
      </div>
    </easy-dialog>
    <easy-dialog :is-show="isShowSuccessDialog" @on-close="toOrderList">
      购买成功！
    </easy-dialog>
    <easy-dialog :is-show="isShowFailDialog" @on-close="toOrderList">
      购买失败！
    </easy-dialog>
  </div>
</template>

<script>
  import EasyDialog from './base/easyDialog'
  import axios from 'axios'
  export default {
    name: 'checkOrder',
    components:{
      EasyDialog
    },
    data () {
      return {
        isShowSuccessDialog:false,
        isShowFailDialog:false
      }
    },
    props:{
      isShowCheckDialog:{
        type:Boolean,
        default:false
      },
      orderId:{
        type: [String,Number]
      }
    },
    methods:{
      checkStatus(){
        axios.post('/api/checkOrder',{orderId:this.orderId})
          .then((res)=>{
            if(res.data.status)
              this.isShowSuccessDialog = true
            else
              this.isShowFailDialog = true
            this.$emit('on-close-check-dialog')
          })
          .catch((res)=>{
            this.isShowFailDialog = true
            this.$emit('on-close-check-dialog')
          })
      },
      toOrderList(){
        this.$router.push({path:'/orderList'})
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
